package cn.hzy.toolkit;

/**
 * <p>
 *  自定义异常 MessageBox
 * </p>
 *
 * @author hzy
 * @since 2020-04-26
 */
public class MessageBox extends RuntimeException {

    private final ApiResult apiResult;

    public MessageBox() {
        super("warn");
        this.apiResult = ApiResult.resultWarn();
    }

    public MessageBox(String msg) {
        super(msg);
        this.apiResult = ApiResult.resultWarn(msg);
    }

    public MessageBox(Object data) {
        super("warn");
        this.apiResult = ApiResult.resultWarn(data);
    }

    public MessageBox(String msg, Object data) {
        super(msg);
        this.apiResult = ApiResult.resultWarn(msg, data);
    }

    /**
     * 获取 ApiResult
     *
     * @return
     */
    public ApiResult getApiResult() {
        return apiResult;
    }

    public static void show() throws MessageBox {
        throw new MessageBox();
    }

    public static void show(String msg) throws MessageBox {
        throw new MessageBox(msg);
    }

    public static void show(Object data) throws MessageBox {
        throw new MessageBox(data);
    }

    public static void show(String msg, Object data) throws MessageBox {
        throw new MessageBox(msg, data);
    }



}
